﻿using SLNGP.Core.GeneticPrograms;
using SLNGP.Core.Individuals;
using System.Linq;

namespace SLNGP.Core.GeneticOpearators
{
    public class CarryoverToNextGeneration : IGeneticOpearator
    {
        public void Execute()
        {
            var individualsToMove =
                Parent.LastRunResults.LastGeneration.Where(
                    i => (SelectionMarkers)i.SelectionMarker == SelectionMarkers.CarryToNextGenerationUnchanged);
         
            foreach (IIndividual individualToMove in individualsToMove)
            {
                Parent.LastRunResults.CurrentGeneration.TryAddUnique(individualToMove);
            }
        }

        public IGeneticProgram Parent { get; set; }
    }
}